package gameEngine.agents.distrebution;

import java.util.HashMap;

import org.apache.log4j.Logger;

import Data.HashMapesOfParameters;

import gameEngine.agents.distrebution.EnumOfDistribution.Distribution_Type;
import gameEngine.agents.distrebution.representation.DistributionRepresentation;
import gameEngine.agents.distrebution.representation.ExponentialRepresentation;
import gameEngine.agents.distrebution.representation.NormalRepresentation;

/**
 * 
 * @author vladimir && alon
 *	Factory that create Distribution
 */
public class DistributionFactory {
	static Logger log = Logger.getLogger(gameEngine.agents.Logger.Massages.MassageFactory.class);
	
	/**
	 * Create and return distribution
	 * 
	 * @param type
	 * @param params
	 * @param competence
	 * @return
	 */
	public static Distribution create( DistributionRepresentation distRepresentation, double competence)
	{
		HashMap<String, Distribution_Type> distributionMap = HashMapesOfParameters.getDistributionMap();
		Distribution_Type type = distributionMap.get(distRepresentation.getDistributionName());
		
		switch(type){
		case EXPONENTIAL_DISTRIBUTION:
			log.debug("Exponential distribution created");	
			try {
				ExponentialRepresentation representation = (ExponentialRepresentation) distRepresentation;
				return new Exponential(representation.getLambda());
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		case FIXED_DISTRIBUTION:
			log.debug("Fixed distribution created");
			return new FixedDistribution(competence);
			
		case NORMAL_DISTRIBUTION:
			log.debug("Normal distribution created");		
			try {
				NormalRepresentation representation = (NormalRepresentation) distRepresentation;
				return new Normal(representation.getMean(), representation.getVariance());
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		case UNIFORM_DISTRIBUTION:
			log.debug("Uniform distribution created");
			return new Uniform();
		}
		
		
		return null;	
	}
	
	
	
	
	
	/**
	 * @author vladimir && alon
	 *
	 *	The class designed to pass parameters of Distribution
	 *	The assumption that the parameters are of type double
	 *	And Indexes in get and set functions start from 1
 	 */
	
	/*public class DistributionParameters
	{
		private double 	vars[] = null;
		

		public DistributionParameters(int numberOfParams) {
			if (numberOfParams > 0)
			{
				//create the array for parameters of type double
				vars = new double [numberOfParams];
			}
		}
		

		public void setParameter(int ndx, double value)
		{
			vars[ndx - 1] = value;
		}
			

		public double getParameter(int ndx)
		{
			return vars[ndx - 1];
		}
		
	}
	*/
	//end of the DistributionParameters
}
